package dao;

import hibernate.HibernateUtil;

import org.hibernate.Session;
import org.hibernate.SessionFactory;

import dto.ItemRemitoDTO;
import entities.EnvioEntity;
import entities.ItemRemitoEntity;

public class ItemRemitoDAO {

	private static ItemRemitoDAO instancia = null;
	private static SessionFactory sf = null;
	
	private ItemRemitoDAO(){}
	
	public static ItemRemitoDAO getInstancia(){
		if(instancia == null){
			sf = HibernateUtil.getSessionFactory();
			instancia = new ItemRemitoDAO();
		} 
		return instancia;
	}
	
	public void grabarItemRemito(ItemRemitoEntity itemRemito){
		Session session = sf.openSession();
		session.beginTransaction();
		session.persist(itemRemito);
		session.flush();
		session.getTransaction().commit();
		session.close();
	}
	
	public void actualizarItemRemito(ItemRemitoEntity itemRemito){
		Session session = sf.openSession();
		session.beginTransaction();
		session.saveOrUpdate(itemRemito);
		session.flush();
		session.getTransaction().commit();
		session.close();
	}
	
	public ItemRemitoEntity LoadItemRemito(int id) 
	{
		Session session = sf.openSession();
		session.beginTransaction();
		ItemRemitoEntity item = (ItemRemitoEntity) session.get(ItemRemitoEntity.class, id);
		session.flush();
		session.getTransaction().commit();
		session.close();
		return item;
	}
}
